<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="../js/vue.js"></script>
    <title>列表渲染</title>
</head>

<body>
    <div id="root">
            输入过滤条件：
            <input type="text" name="keyword" id="keyword" v-model="keyword"><br>
            <button @click="sortType=1">升序</button>
            <button @click="sortType=2">降序</button>
            <button @click="sortType=0">原序</button>
            <h2>成员列表</h2>
        <ul>
            <li v-for="(v,k) in  filteredPersonList" :key="v.id">{{k}}---{{v.name}}---{{v.age}}--{{v.sex}}</li>
        </ul>
    </div>

    <script>
        new Vue({
            el: '#root',
            data: {
                keyword:'',
                sortType:0,
                personList: [
                    { id:'003',name: '张三', age: 12, sex: '女' },
                    { id:'005',name: '李四', age: 11, sex: '男' },
                    { id:'009',name: '王五', age: 12, sex: '女' },
                    { id:'012',name: '赵珊', age: 33, sex: '女' },
                    { id:'015',name: '莉莉', age: 21, sex: '女' },
                    { id:'025',name: '闪迪', age: 37, sex: '女' }
                ]
            },
            computed:{
                filteredPersonList(){
                     let arr = this.personList.filter((p)=>{
                        return p.name.includes(this.keyword)
                    })
                    if(this.sortType){
                      arr = arr.sort((p1,p2)=>{
                           return this.sortType===1? p1.age - p2.age : p2.age - p1.age
                        })
                    }
                    return arr
                }
            }
        })
    </script>
</body>

</html>